﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;

namespace V5_EShop.Controls {
    public partial class IncludeWidget : System.Web.UI.UserControl {
        public string Path { get; set; }
        public string Params { get; set; }
        protected void Page_Load(object sender, EventArgs e) {
            if (!this.IsPostBack) {
                Load_UserControl(Path);
            }
        }

        private void Load_UserControl(string pathName) {
            try {
                UserControl ctl = (UserControl)this.LoadControl("~/Template/Default/" + pathName);
                if (!string.IsNullOrEmpty(this.Params)) {
                    try {
                        Type ucType = ctl.GetType();
                        PropertyInfo ucProperty = ucType.GetProperty("Params");
                        ucProperty.SetValue(ctl, Params, null);
                    }
                    catch {
                    }
                }
                this.Controls.Add(ctl);
            }
            catch (Exception ex) {
                Literal lal = new Literal();
                lal.Text = ex.Message;
                this.Controls.Add(lal);
            }
        }
    }
}